package com.tbit.uqbike.webmanager.controller;

import com.github.pagehelper.PageInfo;
import com.tbit.uqbike.object.pojo.PatrolLog;
import com.tbit.uqbike.object.pojo.statistics.ExportPowerLog;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.PatrolLogService;
import com.tbit.uqbike.webmanager.util.Assert;
import com.tbit.uqbike.webmanager.util.excel.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 巡检日志Controller
 *
 * @author jing
 * @date 2021-04-29
 */
@RestController
@RequestMapping("/patrolLogStat")
public class PatrolLogController extends BaseController {
    @Autowired
    private PatrolLogService patrolLogService;

    /**
     * 查询巡检日志列表
     */
    @GetMapping("/queryPage")
    public JsonResult list(PatrolLog patrolLog) {
        Assert.notNull(patrolLog.getAccountId(), "ver.areaId.notNull");
        Assert.notNull(patrolLog.getEndTime(), "sugar.endRideDt.notNull");
        Assert.notNull(patrolLog.getStartTime(), "sugar.startRideDt.notNull");
        startPage();
        List<PatrolLog> list = patrolLogService.selectPatrolLogList(patrolLog);
        return JsonResult.ok(list, (int) new PageInfo<>(list).getTotal());
    }

    @GetMapping("/statisticsByTime")
    public JsonResult statisticsByTime(PatrolLog patrolLog) {
        Assert.notNull(patrolLog.getAccountId(), "ver.areaId.notNull");
        Assert.notNull(patrolLog.getEndTime(), "sugar.endRideDt.notNull");
        Assert.notNull(patrolLog.getStartTime(), "sugar.startRideDt.notNull");
        return JsonResult.ok(patrolLogService.statisticsByTime(patrolLog));
    }

    /**
     * 导出巡检日志列表
     */
    @GetMapping("/export")
    public JsonResult export(PatrolLog patrolLog) {
        Assert.notNull(patrolLog.getAccountId(), "ver.areaId.notNull");
        Assert.notNull(patrolLog.getEndTime(), "sugar.endRideDt.notNull");
        Assert.notNull(patrolLog.getStartTime(), "sugar.startRideDt.notNull");
//        if(StringUtils.isNull(patrolLog.getAccountUserId())){
//            throw new BaseException(SystemCodeEnum.SELECT_OPERATION_AND_MAINTENANCE_PERSONNEL);
//        }
        List<PatrolLog> list = patrolLogService.selectPatrolLogList(patrolLog);
        ExcelUtil<PatrolLog> util = new ExcelUtil<PatrolLog>(PatrolLog.class);
        return util.exportExcel(list, "巡检");
    }

    /**
     * 统计每个运维人员总数
     */
    @GetMapping("/getByType")
    public JsonResult getByType(PatrolLog patrolLog) {
        Assert.notNull(patrolLog.getAccountId(), "ver.areaId.notNull");
        Assert.notNull(patrolLog.getEndTime(), "sugar.endRideDt.notNull");
        Assert.notNull(patrolLog.getStartTime(), "sugar.startRideDt.notNull");
        startPage();
        List<ExportPowerLog> list = patrolLogService.selectByType(patrolLog);
        return JsonResult.ok(list, (int) new PageInfo<>(list).getTotal());
    }


}
